<?php
/**
 * Created by PhpStorm.
 * User: gui
 * Date: 2019/2/20
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Ramsey\Uuid\Uuid;

class BaseModel extends Model
{
    public $incrementing = false;

    /**
     *  Setup model event hooks
     */
    public static function boot()
    {
        parent::boot ();
        self::creating (function ($model) {
            if (is_null ($model->id)) {
                $model->id = (string)Uuid::uuid4 ();
            }
        });
    }

    public function getRequestAttributes()
    {
        $table = $this->table;
        $arr   = [];
        if ($table) {
            foreach ($this->fillable as $field) {
                $field_key     = 'field.' . $table . '.' . $field;
                $msg           = __ ($field_key);
                $arr[ $field ] = $msg !== $field_key ? $msg : $field;
            }
        }

        return $arr;
    }
}